package ch.fhnw.qualiscan.application.pages;

import java.util.List;
import java.util.Set;

import ch.fhnw.qualiscan.application.models.DomainModel;
import ch.fhnw.qualiscan.application.models.RoleModel;
import ch.fhnw.qualiscan.application.models.SurveyModel;
import ch.fhnw.qualiscan.application.models.UserModel;
import ch.fhnw.qualiscan.application.pages.tabs.NewSurveyTab1;
import ch.fhnw.qualiscan.application.pages.tabs.NewSurveyTab2;
import ch.fhnw.qualiscan.application.pages.tabs.NewSurveyTab3;
import ch.fhnw.qualiscan.application.pages.tabs.NewSurveyTab4;
import ch.fhnw.qualiscan.core.Page;
import ch.fhnw.qualiscan.core.db.helpers.addUserToSurveyArgs;
import ch.fhnw.qualiscan.core.db.helpers.questionWeightArgs;
import ch.fhnw.qualiscan.core.db.pojos.Domain;
import ch.fhnw.qualiscan.core.db.pojos.Role;
import ch.fhnw.qualiscan.core.db.pojos.Survey;

import com.vaadin.ui.Accordion;
import com.vaadin.ui.Form;
import com.vaadin.ui.Label;
import com.vaadin.ui.TabSheet.Tab;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;

import eu.livotov.tpt.i18n.TM;
/**
 * This is the page to add a new Survey.
 * In the first step, the user enters general Information like the Name, deadline and so on.
 * In the second step the questions are weighted.
 * In the third step, the participants are invited.
 * In the fourth step, the wizard is concluded and the invitation mails are sent.
 * @author Kevin Mettenberger
 *
 */
@SuppressWarnings("serial")
public class NewSurvey extends Page {
    
    //Layout Components
    public Label title;
    public Tab tab1;
    public Tab tab2;
    public Tab tab3;
    public Tab tab4;
    public Form generalInfoForm;
    public Form addParticipantsForm;
    public Accordion questionWeightingAccordion;
    public TextField[] participantsRole;
    
    //Tabs
    public VerticalLayout TabComponent1;
    public VerticalLayout TabComponent2;
    public VerticalLayout TabComponent3;
    public VerticalLayout TabComponent4;

    //POJOS
    public Survey survey;
    
    //DB
    public SurveyModel surveyModel;
    public DomainModel domainModel;
    public UserModel userModel;
    public RoleModel roleModel;

    //helpers
    public List<Domain> selectedDomains;
    public List<questionWeightArgs> questionWeights;
    public List<addUserToSurveyArgs> participantsRoleList;
    public List<Role> roleList;

	@Override
	public void initModelsAndHelpers() {
		domainModel = new DomainModel();
		surveyModel = new SurveyModel();
		userModel = new UserModel();
		roleModel = new RoleModel();
	}
	
    @Override
    public void buildLayout() {
    		
    		TabComponent1 = new NewSurveyTab1(this);
    		TabComponent2 = new NewSurveyTab2(this);
    		TabComponent3 = new NewSurveyTab3(this);
    		TabComponent4 = new NewSurveyTab4(this);
    	
            title = textHelper.h1(TM.get("newsurvey.title"));
            addComponent(title);
            
            tabSheet.setHeight("");
            tabSheet.setWidth("100%");
            
            tab1 = tabSheet.addTab(TabComponent1, TM.get("newsurvey.tab1.title"), null);
            tab2 = tabSheet.addTab(TabComponent2, TM.get("newsurvey.tab2.title"), null);
            tab3 = tabSheet.addTab(TabComponent3, TM.get("newsurvey.tab3.title"), null);
            tab4 = tabSheet.addTab(TabComponent4, TM.get("newsurvey.tab4.title"), null);
            
            tab2.setEnabled(false);
            tab3.setEnabled(false);
            tab4.setEnabled(false);
            
            VerticalLayout formWrapper = new VerticalLayout();
    		formWrapper.setMargin(true);
            
            addComponent(tabSheet);
    }

	@Override
	public void setNeededPermissions() {
		neededPermissions.add("loggedIn");
		neededPermissions.add("createsurvey");
	}

	@Override
	public void initComponents() {
	}

	@Override
	public void thirdParameterChanged(String thirdParameter) {
	}

}
